package sf.model.fields;

import java.awt.FlowLayout;

import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

@Deprecated
public class BoolFieldNew extends JPanel implements Field {

	private static final long serialVersionUID = 1L;

	private ButtonGroup buttonGroup;
	private JRadioButton buttonYes;
	private JRadioButton buttonNo;

	public BoolFieldNew(String name) {
		setName(name);
		setLayout(new FlowLayout());

		buttonGroup = new ButtonGroup();

		buttonYes = new JRadioButton("Da", false);
		buttonNo = new JRadioButton("Ne", false);

		buttonGroup.add(buttonYes);
		buttonGroup.add(buttonNo);

		add(buttonYes);
		add(buttonNo);
	}

	public Object getValue() {
		if (buttonYes.isSelected())
			return true;
		else if (buttonNo.isSelected())
			return false;
		else
			return null;
	}

	public void setValue(Object value) {
		if (value == null) {
			clear();
		} else if ((Boolean) value == true) {
			buttonYes.setSelected(true);
		} else if ((Boolean) value == false) {
			buttonNo.setSelected(true);
		}
	}

	public void clear() {
		buttonGroup.clearSelection();
	}
}
